package com.itboye.jigongbao.activity

import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.itboye.jigongbao.R
import com.itboye.jigongbao.app.MyApplication
import com.itboye.jigongbao.base.BaseActivity
import com.itboye.jigongbao.bean.JiYiBiBean
import com.itboye.jigongbao.enums.DetailEnums
import com.itboye.jigongbao.retrofit.base.ResultEntity
import com.itboye.jigongbao.retrofit.presenter.UserPrestener
import com.itboye.jigongbao.utils.TitleBarUtils
import com.itboye.jigongbao.utils.ToastUtil.ByAlert
import kotlinx.android.synthetic.main.activity_he_zhang_detail.*
import org.json.JSONObject
import java.util.*

class HeZhangDetailActivity : BaseActivity(), Observer {
    override fun update(p0: Observable?, p1: Any?) {

        var entity: ResultEntity = p1 as ResultEntity
        ByAlert.alert(entity.msg)
        if (entity.code != 0) {
        } else {
            when (entity.eventType) {
                UserPrestener.By_JgbRecord_audit_Success -> {
                    finish()
                }
                UserPrestener.By_JgbRecord_audit_Fail -> {
                }
            }
        }
    }

    var iv_actionbar_left: ImageView? = null
    var detailEnums: DetailEnums? = null
    var li_bottom_button: LinearLayout? = null
    var txt_hezhangdetail_name_value: TextView? = null
    var txt_hezhangdetail_mobile_value: TextView? = null
    var txt_gongren_hezhangdetail_name_value: TextView? = null
    var txt_gongren_hezhangdetail_mobile_value: TextView? = null
    var txt_hezhangdetail_xiangmu_value: TextView? = null
    var txt_hezhangdetail_gongshi_value: TextView? = null
    var txt_hezhangdetail_jiabanshichang_value: TextView? = null
    var txt_hezhangdetail_jigongdanwei_value: TextView? = null
    var txt_hezhangdetail_jiabanjigongdanwei_value: TextView? = null
    var txt_hezhangdetail_gongzidanwei_value: TextView? = null
    var txt_hezhangdetail_total_value: TextView? = null

    var tv_pass: TextView? = null//通过
    var tv_doubtful: TextView? = null//存疑

    var userPresenter: UserPrestener? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_he_zhang_detail
    }

    var bean: JiYiBiBean.JiYiBiEntity? = null
    override fun initData() {
        TitleBarUtils().initTitlebarStyle1(this, this!!.trans_action_bar_hezhang_detail!!, intent.getStringExtra("title"), R.drawable.img_back, "", 0, "")
        userPresenter = UserPrestener(this)
        detailEnums = intent.getSerializableExtra("type") as DetailEnums?
        bean = intent.getSerializableExtra("model") as JiYiBiBean.JiYiBiEntity
        var extra: JSONObject? = null
        try {
            extra = JSONObject(bean!!.extra)
        } catch (e: Exception) {

        }
        //工头点工
        txt_hezhangdetail_name_value!!.setText(bean!!.overseer_name)
        txt_hezhangdetail_mobile_value!!.setText(bean!!.overseer_mobile)
        txt_gongren_hezhangdetail_name_value!!.setText(bean!!.worker_name)
        txt_gongren_hezhangdetail_mobile_value!!.setText(bean!!.worker_mobile)
        txt_hezhangdetail_xiangmu_value!!.setText(bean!!.project_title)
        when (detailEnums) {
        //---------------------------------------------//
            DetailEnums.YIJIBI_FOREMAN_DIANGONG, DetailEnums.YIJIBI_WORKER_DIANGONG -> {
                if (extra!!.has("normal_worktime")) {
                    txt_hezhangdetail_gongshi_value!!.setText(extra.getString("normal_worktime") + "时")
                }
                if (extra.has("over_worktime")) {
                    txt_hezhangdetail_jiabanshichang_value!!.setText(extra.getString("over_worktime") + "时")
                }
                txt_hezhangdetail_total_value!!.setText("${bean!!.money / 100}")
            }
            DetailEnums.YIJIBI_FOREMAN_BAOGONG, DetailEnums.YIJIBI_WORKER_BAOGONG -> {
                //工头包工
                //工时--->子项目
                txt_hezhangdetail_gongshi.text = "子项目"
                txt_hezhangdetail_gongshi_value!!.setText(bean!!.sub_title)
                //加班时长-->数量
                txt_hezhangdetail_jiabanshichang.text = "数量"
                if (extra!!.has("count")) {
                    txt_hezhangdetail_jiabanshichang_value!!.setText(extra.getString("count"))
                }
                if (extra!!.has("price")) {
                }
                txt_hezhangdetail_total_value!!.setText("${bean!!.money / 100}")
                //加班记工单位、工资单位隐藏
                txt_hezhangdetail_jiabanjigongdanwei.visibility = View.GONE
                txt_hezhangdetail_gongzidanwei.visibility = View.GONE
                txt_hezhangdetail_jiabanjigongdanwei_value!!.visibility = View.GONE
                txt_hezhangdetail_gongzidanwei_value!!.visibility = View.GONE
            }
            DetailEnums.YIJIBI_FOREMAN_JIEZHI, DetailEnums.YIJIBI_WORKER_JIEZHI -> {
                //工头借支
                //工时--->借支金额
                txt_hezhangdetail_gongshi.text = "借支金额"
                txt_hezhangdetail_gongshi_value!!.setText("${bean!!.money / 100}")
                //加班记工单位、工资单位隐藏
                txt_hezhangdetail_jiabanjigongdanwei.visibility = View.GONE
                txt_hezhangdetail_gongzidanwei.visibility = View.GONE
                txt_hezhangdetail_jiabanjigongdanwei_value!!.visibility = View.GONE
                txt_hezhangdetail_gongzidanwei_value!!.visibility = View.GONE
                txt_hezhangdetail_jigongdanwei.visibility = View.GONE
                txt_hezhangdetail_jiabanshichang.visibility = View.GONE
                txt_hezhangdetail_jiabanshichang_value!!.visibility = View.GONE
                txt_hezhangdetail_jigongdanwei_value!!.visibility = View.GONE
                txt_hezhangdetail_total_value!!.setText("" + bean!!.money / 100)
            }
            DetailEnums.YIJIBI_FOREMAN_JIESUAN, DetailEnums.YIJIBI_WORKER_JIESUAN -> {
                //工头结算
                //工时--->结算金额
                txt_hezhangdetail_gongshi.text = "结算金额"
                txt_hezhangdetail_gongshi_value!!.setText("" + bean!!.money / 100)
                //加班记工单位、工资单位隐藏
                txt_hezhangdetail_jiabanjigongdanwei.visibility = View.GONE
                txt_hezhangdetail_gongzidanwei.visibility = View.GONE
                txt_hezhangdetail_jiabanjigongdanwei_value!!.visibility = View.GONE
                txt_hezhangdetail_gongzidanwei_value!!.visibility = View.GONE
                txt_hezhangdetail_jigongdanwei.visibility = View.GONE
                txt_hezhangdetail_jigongdanwei_value!!.visibility = View.GONE
                txt_hezhangdetail_jiabanshichang.visibility = View.GONE
                txt_hezhangdetail_jiabanshichang_value!!.visibility = View.GONE
                txt_hezhangdetail_total_value!!.setText("${bean!!.money / 100}")
            }

//        //---------------------------------------------//
//            DetailEnums.WAGESBILLS_FOREMAN -> {
//                //工资清单—>工头
//            }
//            DetailEnums.WAGESBILLS_WORKER -> {
//                //工资清单—>工人
//            }
//
//        //---------------------------------------------//
//            DetailEnums.HEZHANG_TIMES_FOREMAN -> {
//                //审账—>工头
//                li_bottom_button!!.visibility = View.VISIBLE
//            }
//            DetailEnums.HEZHANG_THINGS_FOREMAN -> {
//                //审账—>工头
//                li_bottom_button!!.visibility = View.VISIBLE
//            }
//            DetailEnums.HEZHANG_TIMES_WORKER -> {
//                //核账—>工人->
//                li_bottom_button!!.visibility = View.VISIBLE
//            }
//            DetailEnums.HEZHANG_THINGS_WORKER -> {
//                //核账—>工人->
//                li_bottom_button!!.visibility = View.VISIBLE
//            }
        }
        var booleanValue = intent.getBooleanExtra("shenhe", false)
        if (booleanValue) {
            li_bottom_button!!.visibility = View.VISIBLE
        } else {
            li_bottom_button!!.visibility = View.GONE
        }
    }

    override fun onClick(p0: View?) {
        when (p0) {
            iv_actionbar_left -> {
                finish()
            }
            tv_pass -> {
                //1 通过
                userPresenter!!.By_JgbRecord_audit(bean!!.id, MyApplication.instance!!.loginInfo!!.getUid(), 1, this)
            }
            tv_doubtful -> {
                //2 存疑
                userPresenter!!.By_JgbRecord_audit(bean!!.id, MyApplication.instance!!.loginInfo!!.getUid(), 2, this)
            }
            else -> {
            }
        }
    }


}
